﻿using System;
using System.Linq;
using Biz.Buffer;
using Biz.EF.Platform.SG;
using Hjt212Parser;
using log4net;

namespace Biz.Process
{
   public class ProcessorStatus
    {
        private static readonly ILog Log = LogManager.GetLogger(typeof(ProcessorStatus));
        public static void ProcessOffline(string content)
        {
            try
            {
                using (var contextTarget = new PlatformXpfContext())
                {
                    var mn = Parser.GetStringByKey("MN", content);
                    if (string.IsNullOrEmpty(mn)) return;
                    var info = CommonInformation.GetLetportByMn(mn);
                    if (info == null) return;
                   
                    var masterMonitor =
                        contextTarget.主实时监控.Where(t => t.企业基本信息ID == info.企业基本信息ID)
                            .FirstOrDefault(t => t.企业排口ID == info.ID);
                    if (masterMonitor == null) return;
                    masterMonitor.在线状态ID = 1202;
                    masterMonitor.在线状态时间 = Parser.GetDateTimeByKey("DataTime", content);
                    contextTarget.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                Log.Error(ex);
            }
        }
    }
}
